package com.yumis.service.modules.shop.service.Impl;

import com.yumis.service.common.enums.HttpState;
import com.yumis.service.common.exception.GlobalException;
import com.yumis.service.common.vo.Response;
import com.yumis.service.model.pojo.Shop;
import com.yumis.service.model.pojo.ShopPosition;
import com.yumis.service.modules.shop.mapper.ShopPositionMapper;
import com.yumis.service.modules.shop.service.ShopPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class ShopPositionServiceImpl implements ShopPositionService {
    @Resource
    private ShopPositionMapper shopPositionMapper;

    @Override
    public void addShopPosition(ShopPosition shopPosition) {
        int currTime = (int) (System.currentTimeMillis()/1000);
        shopPosition.setCreateTime(currTime);
        shopPosition.setUpdateTime(currTime);
        int i=shopPositionMapper.insert(shopPosition);
        if (i!=1){
            throw new GlobalException(Response.buildResponse(HttpState.CREATED_FAILED));
        }
    }

    @Override
    public void deleteShopPositionById(Long id) {
        int i=shopPositionMapper.deleteByPrimaryKey(id);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.DELETE_ERROR));
        }
    }

    @Override
    public ShopPosition queryShopPositionById(Long id) {
        ShopPosition shopPosition=shopPositionMapper.selectByPrimaryKey(id);
        if (shopPosition ==null || shopPosition.equals("") ){
            throw new GlobalException(Response.buildResponse(HttpState.DATA_NOT_FOUNT));
        }
        return shopPosition;
    }

    @Override
    public void updateShopPosition(ShopPosition shopPosition) {
        shopPosition.setUpdateTime((int) (System.currentTimeMillis()/1000));
        int i=shopPositionMapper.updateByPrimaryKeySelective(shopPosition);
        if (i !=1){
            throw new GlobalException(Response.buildResponse(HttpState.UPDATE_ERROR));
        }
    }
}
